home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / program / gcc / ixemul40.lha / ixemul-bin / README < prev    next >
Text File  |  1995-05-21  |  32KB  |  695 lines

  1. Markus M. Wild                             March 16, 1992
  2.  
  3. This  is  the  second public release of my shared library, that should make
  4. porting  programs  originally  written to be run on a **IX/BSD system to be
  5. much easier on the Amiga computer running AmigaDOS.
  6.  
  7. ---------------------------------------------------------------------------
  8.             COPYRIGHT restrictions
  9.  
  10. The  source  code  shipped  with this library is subject to the GNU LIBRARY
  11. GENERAL PUBLIC LICENSE, please look at the file COPYING.LIB that comes with
  12. this distribution.  If not, write to the
  13.   Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14.  
  15. NOTE:   
  16. There  are  lots  of  files  subject to  other Copyrights, especially those
  17. Copyright  by the Regents of the University of California.  In those cases,
  18. the  specified  Copyright restriction applies TO EACH SUCH SINGLE FILE, but
  19. not the arrangement of putting it in this library.  With this restriction I
  20. want to enforce consistency of this library.
  21.  
  22. After reading the COPYING.LIB file, you'll notice, that a program that just
  23. uses the library by using OpenLibrary(), and calling functions in it, is to
  24. be  considered  as  a  `work that uses the Library', and 5.  of COPYING.LIB
  25. says  for this case:  " Such a work, in isolation, is not a derivative work
  26. of the Library, and therefore falls outside the scope of this License."
  27.  
  28. Since  I  declare  the  glue  functions  created  by  compiling and running
  29. gen_glue.c  (in lib/) to be in the Public Domain (thus not to be covered by
  30. any  license),  your  compiled  and  linked  executable  will  NOT become a
  31. derivative  of  the  library, and will thus not be subject to this license.
  32. Thus,  you  may  use  the  compiled version of the glue files and the stdio
  33. functions,  libc.a (except alloca.c, please see the copyright notice in its
  34. header.   Use  the  builtin alloca() (__builtin_alloca() to be explicit) in
  35. all  situations  where this is possible) and crt0.o in a commercial product
  36. without  making  it a derivative of the library and thus make it subject to
  37. the   library   license.   However,  you  must  tell  your  customers  that
  38. ixemul.library  is  free software according to this license, and where they
  39. can get a copy of its source code.
  40.  
  41. ---------------------------------------------------------------------------
  42.  
  43. Now that the legal stuff is over, some comments to this library.
  44.  
  45.  
  46.  
  47. *** note to upgraders (that is, people who already worked with the previous
  48. *** versions): The following text is the (slightly edited) README file of
  49. *** the previous version. If you decide to skip to the really new stuff, you
  50. *** might miss important information of things that have changed, so if at
  51. *** all possible read the first part as well! 
  52.  
  53.  
  54.  
  55. 68000 users, take care!
  56. =======================
  57.  
  58. I tried to be fully 68000 compatible (this is important in the signal
  59. code), but since I don't have a 68000 equipped Amiga anymore, I can't test
  60. whether the library really works under this environents.  Please tell me,
  61. if you encounter problems!  Since this is the second library release,
  62. chances are high that most things should work, as I did extensive bugfixing
  63. in this area over the past months.  The warning still holds though, I just
  64. *can't* test this compatibility issue myself!
  65.  
  66. I always wanted a library, that would emulate as much as possible of a
  67. **IX/BSD environment on the Amiga, so that programs (usually programming
  68. tools) written for **IX/BSD could be ported in a quick and straight forward
  69. way to the Amiga.  I guess the library accomplishes this goal fairly well.
  70.  
  71.  
  72.  
  73. What it is and what it isn't
  74. ============================
  75.  
  76. The design of the library was therefore guided towards **IX/BSD
  77. compatibility, and *not* :
  78.  o to be too conservative with resources 
  79.  o to be particularly conformant to Amiga habits. Thus if I had to decide
  80.    whether I should make a function act more like an Amiga function or
  81.    more like a **IX/BSD one, I decided for the latter. As an example:
  82.    _cli_parse() does wildcard expansion, and tries to apply more or less
  83.    **IX/BSD shell semantics to an argument line, it doesn't call
  84.    ReadArgs().
  85.    The types used in my own source code are all from sys/types.h (except
  86.    BPTR). I don't think capitalized identifiers should be used for typedef'd
  87.    types. According to C-conventions, anything written in captials should
  88.    be `#undef'inable, which typedefs aren't. Thus if you write contributions
  89.    to be included into the official distribution of this library, code
  90.    according to this. Use `u_char' and not UBYTE, etc. I don't care that
  91.    this is against the Commodore coding standard, this is my code, and
  92.    I decide what I like and what not.
  93.  o to be particularly suited for inclusion into a shared library, although
  94.    most things *are* shared now. What I'd really want for the Amiga is 
  95.    the concept of a dynamic linker.
  96.  
  97. On the other hand, it should be:
  98.  o expandable. As an example, a file descriptor already can refer to `real'
  99.    files, directories, memory buffers treated as files. I plan to add 
  100.    sockets in some next release (Commodore: please get out some examples 
  101.    on how to use SANA-II stuff, so my sockets can be compatible!)
  102.  o patchable. If you want some function to behave differently, you can
  103.    SetFunction() it, and the rest of the library should use your new entry.
  104.    NOTE: I used this only for major functions, that may reasonably change. 
  105.      I didn't call functions like strcmp(), strlen(), bcopy() that way for
  106.          efficiency reasons (and my lazyness to change the whole string/
  107.          and other libraries;-)))
  108.    This version doesn't particularly follow this goal very well, mostly
  109.    stdio is still the original BSD code, and doesn't use syscall()...
  110.  
  111.  
  112.  
  113. Difference to `usual' Amiga shared libraries
  114. ============================================
  115.  
  116. The library is designed to be used by C, and not by assembly.  So
  117. parameters are passed on the stack rather than in registers.  This also
  118. means that there is no `fd' file, and you can't use any current library
  119. call  pragmas  to  access  its  functions.   Recall  though,  that  calling
  120. functions  of  ixemul.library  inline  will  not  result  in  an  order  of
  121. improvement  as  calling  standard  library  functions  inline.   The  glue
  122. functions  don't have to shuffle arguments from and to the stack, they just
  123. do a jump over the base table and are therefore very short and very fast.
  124.  
  125. I provided revision control in the startup code. Thus if you get a program
  126. written for a newer revision of the library than you currently have, a 
  127. warning requester tells you about this, you can still use the program though.
  128. I don't believe in bumping up the version counter because of every small 
  129. improvement. Bumping up the version means you can't use any older versions at
  130. all. Bumping up the revision just gives you an annoying requester (and
  131. perhaps an `illegal action' trap though..) that you should upgrade.
  132.  
  133. As some kind of replacement for an fd file I use the <sys/syscall.def> file.
  134. It contains lines of the form
  135.   SYSTEM_CALL (name_of_call, entry_number)
  136. Where `name_of_call' is the name you'd use in a C program using the library
  137. (for example write, abort, unlink, etc), and `entry_number' gives the number
  138. of the system call used in syscall(). You can convert this number into
  139. a more common _LVO for the Amiga by doing:
  140.   _LVO = -6*(entry_number + 4)
  141.  
  142. For examples how <sys/syscall.def> can be used, look at <sys/syscall.h>,
  143. `library/start.s' and `lib/gen_glue.c'.
  144.  
  145.  
  146.  
  147. Where to use it
  148. ===============
  149.  
  150. Libc.a should be the one and only C library you need to get most of your
  151. programs linked correctly with the GNU CC compiler.  For some math-
  152. oriented stuff you'll also need a math library, libm.a (the BSD math
  153. library) should be suited fine for this. Just link with `-lm'.
  154.  
  155.  
  156.  
  157. If you want to recompile
  158. ========================
  159.  
  160. I provided Makefiles for the most directories (for all by now ?).  Those
  161. Makefiles assume a decent Make tool, I'm currently using a version (hacked
  162. for the Amiga) of DMake (not the one from Matt Dillon, sources are on
  163. wuarchive.wustl.edu), you'll have to rewrite the Makefiles if you don't use
  164. DMake, as the .LIBRARY feature seems to be unique, other `make's use other
  165. techniques to accomplish the same goal, if they support it at all.
  166.  
  167. Sources are written for compilation by GCC. You might be able to compile
  168. 95% of them with any ordinary ANSI-C compiler, but there are cases where
  169. you have to change things for non-GCC environments (mostly asm() situations).
  170.  
  171. For recompilation, see also the following comments in `How complete are the
  172. headers'.
  173.  
  174. To regenerate libc.a, cd into lib/ and type `make'.  Then cd into `glue',
  175. enter `/gen_glue', and wait for it to finish (can take quite some time, it
  176. has to create more than 400 files !).  Then `make' in this directory and cd
  177. back to lib/.  You may now (cross your fingers and) type `make libc.a', and
  178. if you have sksh configured as system shell, libc.a should now be built
  179. automatically.  If something doesn't work, look at the Makefile and do it
  180. manually ;-)
  181.  
  182. As an explanation to the separate compilation of crt0.o:  this has to be
  183. compiled with `-fwritable-strings', since you have to be sure that ENTRY()
  184. is the first thing in the generated object file.  If you don't specify
  185. `-fwritable-strings', you'll get string constants at the first executable
  186. address in your programs, and this will get you (and your computer) into
  187. meditation if you try to execute such programs ;-))
  188.  
  189. To regenerate ixemul.library, cd into string/, gen_library/, stdlib/,
  190. gnulib/, gnulib20/, stdio_2/ and at last library/, and type `make'.  At the
  191. end, you should get a current version of ixemul.library.
  192.  
  193. Note: the library is currently compiled in a way that makes it easy for me
  194. to have a debugged version or not, ie. the debugging statements stay in
  195. the code, but the kprintf() function is either linked with the library
  196. to get a debugging version, or stubbed out to get a working version. When the
  197. library gets more stable, parts of it can be compiled by inlining code
  198. to the library, instead of going thru syscall().
  199.  
  200.  
  201.  
  202. If you want to write code that uses the library
  203. ===============================================
  204.  
  205. Code like you would on a **IX/BSD system, thus DON'T USE any information
  206. private to the library, especially don't use any information that
  207. tc_TrapData points to.  This data is subject to change in every release of
  208. the library, and you may only access its variables thru library access
  209. functions!  This restriction fully applies as well to applications that
  210. SetFunction() some functions of the library.  So if you for example write
  211. your own memory allocation functions, you may NOT use the space the library
  212. malloc() function uses for your own purpose.  I may decide in a later
  213. release of the library to use a different malloc() implementation that
  214. uses different data in the user area, and then your code almost certainly
  215. would trash innocent variables!
  216.  
  217.  
  218.  
  219. How complete are the headers
  220. ============================
  221.  
  222. The header files distributed in `include/' are all you need - except the 
  223. Amiga specific header files copyright by Commodore-Amiga. You either have
  224. to get them from a commercial compiler, or order them from CATS.
  225. If you don't intend to compile Amiga specific programs, you don't need
  226. those headers at all.
  227.  
  228. You need to make one change to one of those Amiga headers to avoid
  229. duplicate definition of a datatype:
  230.  
  231. The <devices/timer.h> file includes the following definition:
  232.     struct    timeval    {
  233.         ULONG tv_secs;
  234.         ULONG tv_micro;
  235.     };
  236. Please comment this definition out, and add 
  237.     #include <sys/time.h>
  238. somewhere at the beginning of the file, and instead of the above definition,
  239. put
  240.     #define tv_secs  tv_sec
  241.     #define tv_micro tv_usec
  242. That way, you can use the timeval structure defined in <sys/time.h> as well
  243. as the one defined in <devices/timer.h>. The structures are identical, but
  244. the field names are not (sigh..).
  245.  
  246.  
  247. I included more or less all headers from 4.3BSD-net2, except those that 
  248. refer to really **IX/BSD specific material in the kernel. I included more
  249. headers that are currently used and supported, just to make life easier for
  250. people using **IX/BSD sources under AmigaDOS. Among the things not supported
  251. currently are networking (sockets) and process management (fork, eg).
  252. Signals on the other hand *are* implemented, see the special section for
  253. restrictions.
  254.  
  255.  
  256.  
  257. How BSD signals are implemented
  258. ===============================
  259.  
  260. I tried to implement as much of Berkeley style signals as possible on the
  261. Amiga. This includes a trap handler as well as an asynchronous signal 
  262. facility. The one thing not implemented are interruptable system calls.
  263. Since there are no `real' system calls on the Amiga (ie. no calls that are
  264. executed in Supervisor mode), those calls cannot normally be interrupted,
  265. ie. forced to return to their caller. So all functions except sigpause()/
  266. sigsuspend() will return to where they were interrupted if a signal 
  267. occurs.
  268.  
  269. These 32 new signals are 32 really new signals, not tied to any of the 32
  270. Amiga signals provided by Exec.  The one exception is SIGBREAKB_CTRL_C,
  271. which is by default bound to generate a SIGINT.
  272.  
  273. Signal handlers are called with the following arguments:
  274.   void 
  275.   signal_handler (int signo, int code, void *address, struct sigcontext *sc)
  276.  
  277. Where
  278.   signo:  is the signal number that occured, see <signal.h>
  279.   code:   is a more specific characterization of signo available with some
  280.       signals. It is available with all signals that are generated
  281.       because of a processor exception, and then contains the format
  282.       identifier of the exception frame (this is correct even for the
  283.       68000, where such an identifier is faked, ie. it doesn't really
  284.       exist). Thus a `division by zero' exception would be invoked by
  285.         signal_handler (SIGFPE, 0x2014, address, sc)
  286.   address:address referrs to the instruction that caused the signal.
  287.   sc:     please don't use sc, as it may change in the future. It contains
  288.       the context to restore after the signal handler returns.
  289.  
  290. ***************************************************************************
  291. If you use signals in your own code, make sure that you never allow a 
  292. situation, where when your program is interrupted resources stay allocated!
  293. ***************************************************************************
  294.  
  295. That is, the following example is BAD :
  296.     ..
  297.     fh = Open ("foobar", MODE_OLDFILE);
  298.     if (fh)
  299.       {
  300.         .. do something with it ..
  301.         Close (fh);
  302.       }
  303.  
  304. If your program is interrupted and terminated after you got your file handle,
  305. `fh' will never be closed! There are two sollution to get around this problem,
  306. either use library functions from ixemul.library, or explicitly mask signals
  307. while you have resources locked. Thus in this example, either do:
  308.  
  309.     fd = open ("foobar", O_RDWR);
  310.     if (fd >= 0)
  311.       {
  312.         .. do something with it ..
  313.         close (fd);
  314.       }
  315.  
  316. in that case the library will do resource tracking on fd. Or explicitly mask
  317. the signals:
  318.  
  319.     omask = sigsetmask (~0);    /* mask all signals */
  320.     fh = Open ("foobar", MODE_OLDFILE);
  321.     if (fh)
  322.       {
  323.         .. do something with it ..
  324.         Close (fh);
  325.       }
  326.     sigsetmask (omask);        /* reset the mask */
  327.  
  328. Note that the second sollution is worse than the first one, because the
  329. user may send the process a non-maskable signal that would terminate the
  330. process unconditionally (SIGKILL does this), and don't forget that the user
  331. isn't able to break your program as long as you have signals masked!
  332.  
  333. Ixemul.library does resource tracking on all file-related functions (create(),
  334. open(), dup(), pipe()) and on memory allocations thru malloc() and realloc().
  335. Thus if you use those functions instead of dos.library and exec.library 
  336. functions, you don't need any clever resource tracking stuff to do on your
  337. own, that's what the library is for ;-)
  338.  
  339. If you use Amiga specific resources like Windows and Screens from
  340. Intuition, make sure to add an atexit() handler to close those resources,
  341. if the user should decide to interrupt your program.  Before the program is
  342. left, the chain of registered atexit-handlers is called in exit().  So
  343. PLEASE NEVER EVER call _exit() if you have registered any custom atexit()
  344. handlers.  It is a bad habbit anyway, but normally you may call _exit()
  345. without resource lossage (stdio won't flush its buffers, but that's about
  346. all), as long as you close ixemul.library after use, and this IS A MUST, as
  347. for every Amiga shared library anyway.
  348.  
  349. I provided a new unique Amiga specific signal called SIGMSG. If you set up
  350. a handler for this signal, then
  351.  o  the default mapping from SIGBREAKB_CTRL_C into SIGINT will no longer
  352.     occur
  353.  o  your handler is called with the following arguments
  354.       signal_handler (SIGMSG, new_exec_signal_mask)
  355.  
  356. In this case, you have to deal with Exec signals yourself, so don't forget
  357. to clear those signals that you want to receive notification about again
  358. later. 
  359. Thus if you'd want to handle SIGBREAKB_CTRL_C yourself, don't forget to
  360.  
  361.   SetSignal (0, SIGBREAKF_CTRL_C)
  362.  
  363. at the end of the handler, or you'll never get notification about that
  364. signal again.
  365.  
  366.  
  367. If your program is interrupted by a signal and the default action of that
  368. signal is to terminate your program, and you didn't set up a handler to deal
  369. with that signal, your program is terminated by calling `exit (128 + signo)'.
  370. There are no core-dumps yet, I first have to think about a useful format
  371. for a debugger that takes care of the Amiga's memory architecture.
  372.  
  373.  
  374. The signal implementation uses some of the Berkeley kernel sources of the
  375. 4.3BSD-reno release for the hp300. I didn't disable everything that isn't
  376. implemented currently, so you might face strange behavior if you currently
  377. try to send a SIGSTOP to a process using the library, you better not ;-))
  378.  
  379. Currently supported are the following signals:
  380.   SIGINT:    bound to ^C (SIGBREAKB_CTRL_C) unless there is a SIGMSG handler
  381.   SIGILL:    generated by some hardware exceptions
  382.   SIGFPE:    generated by some hardware exceptions
  383.   SIGBUS:    generated by some hardware exceptions
  384.   SIGALRM:   if you use alarm() or the ITIMER_REAL interval timer
  385.   SIGVTALRM: if you use the ITIMER_VIRTUAL interval timer
  386.   SIGPROF:   if you use the ITIMER_PROF interval timer
  387.   SIGMSG:    if you provide a signal handler for it
  388.   SIGCHLD:   a vfork()'d child died (or stopped ?;-))
  389.   SIGSEGV:   the programs used more stack than you allowed it to (see below)
  390.  
  391. more are to follow.  You may send any of the 32 signals to a process using
  392. the library with the `kill ()' function, the default behavior of a process
  393. is described in a **IX/BSD man page for signals.  As mentioned above,
  394. stopping a process isn't currently implemented, and may produce strange
  395. behavior...
  396.  
  397.  
  398.  
  399. Compatibility
  400. =============
  401. I tried to port some commonly used programs to the Amiga using this
  402. library. And the following programs were quite easy to port:
  403.  o patch
  404.  o GNU tar-1.10  (the first Amiga tar that knows about symlinks ;-))
  405.  o GNU find-2.2 (replace the fork,exec-stuff with a call to ssystem() )
  406.  o BSD ar, ranlib (with DMake even things like VPATH=../ar work ;-))
  407.  o GNU cc ;-))
  408.  o DMake 
  409.  o ...
  410. As a guideline, if you find stuff that uses fork,exec,wait stuff, try to
  411. replace it with a call to ssystem()/system().  system() corresponds to the
  412. usual **IX/BSD library function, it runs the argument thru the current
  413. shell.  ssystem() is some lower level execution function, that under 1.3
  414. uses ARPs SyncRun() function (that's where the name came from ;-)), and
  415. under 2.0 uses my own code to find the executable (searches the users
  416. PATH), and tries to do interpreter expansion on the file (the thing with #!
  417. rsp.  ;!  as the first two characters. Please see the `library/__load_seg.c'
  418. file for more details;-)).  
  419. Note for second version:  beginning support for vfork(), exec*() and wait()
  420. is provided, please use with care!
  421.  
  422.  
  423.  
  424. ***
  425. *** New stuff as of March 16, 1992
  426. ***
  427. ***************************************************************************
  428.  
  429.  
  430. The library got quite a bit larger, and executables using it get smaller
  431. and smaller ;-) This is mainly due to the fact that now stdio is included
  432. in the shared library, and no longer in the statically linked libc.a. Since
  433. I switched to the newest BSD stdio implementation, compatibility to older
  434. versions was no longer required, and you get additional functionality in
  435. the same run (setvbuf() for example). There is one compatibility problem
  436. though:
  437.  
  438. *************************************************************************
  439. Don't use the 1.40 libg++.a together with this new library, 1.40 libg++.a
  440. has intimate knowledge of the old stdio implementation, and won't work
  441. with this one (you'll probably get linktime errors, missing _iob). Use 
  442. the 2.0 libg++.a instead (soon on amiga.physik.unizh.ch as well).
  443. *************************************************************************
  444.  
  445. The main new thing is `ixconfig', which you find in the bin/ directory.
  446.  
  447.  
  448.  
  449. ixconfig
  450. ========
  451.  
  452. ixconfig is used to tailor the library to your requirements and/or 
  453. habits. Just running ixconfig without options prints the current settings,
  454. which look like this by default:
  455.  
  456.     1> ixconfig
  457.     Translate . and .., translate /, don't translate symlinks,
  458.     allow AmigaDOS notation, membuf size = 0,
  459.     red zone size = 0, stack watcher is disabled (and not active).
  460.  
  461. Here's an explanation of those settings:
  462. "translate . and .."    mapping of `a/./b/../c' into `a/b//c' is enabled
  463. "translate /"        mapping of `a///b' into `a/b' and `/device' into
  464.             `device:' is enabled. Note: You can't currently get
  465.             a directory of the virtual `/' directory this way.
  466. "translate symlinks"    apply `translate /' to contents of symlinks as well
  467. "AmigaDOS notation"    allow use of device names in the colon form 
  468.             (ie. sys: instead of /sys), and don't force `..'
  469.             notation.
  470. "membuf size"        if you set a non-zero value here, all files upto
  471.             that value, that are opened O_RDONLY are read
  472.             into memory, and read/seek operations occur in memory.
  473. "red zone size N"    size of `safety net'. If your program uses
  474.             so much stack, that the stack pointer is more
  475.             than N bytes near the stack bottom, your program
  476.             is sent a SIGSEGV signal. Red zone size is used
  477.             when starting a new process, if you change it later,
  478.             no already running processes are affected.
  479. "stack watcher"        global toggle. If disabled, no SIGSEGV signal is
  480.             sent to any program (but if red zone size is > 0,
  481.             the process keeps a pointer, so that if you reenable
  482.             the stack watcher, SIGSEGV will be sent again).
  483.             
  484. This was an explanation of the output of ixconfig, to change those values
  485. type `ixconfig -h' for an explanation on the available switches. One
  486. switch might need further explanation: `-s'. If you specify `-s', ixconfig
  487. goes to sleep after setting the new parameters, and won't return until you
  488. break it with ^C. This is the preferred switch if you run ixconfig from your
  489. startup-sequence in the background, as then your changes can't be undone by
  490. flushing the library (ixconfig keeps it open, so that Expunge() can't flush
  491. it).
  492.  
  493.  
  494.  
  495. Some notes to vfork() and friends
  496. =================================
  497.  
  498. **IX/BSD process management is one of the most nasty design differences
  499. between AmigaDOS ans **IX/BSD. `fork()' for example is hardly possible to
  500. implement on AmigaDOS, as it requires to create an identical copy of the
  501. parent process. This is only feasible with virtual memory, where processes
  502. can be mapped at equal places in memory. Under AmigaDOS this would have
  503. to be simulated by copying of stack and malloc'd data whenever a process
  504. is activated, and copying them to a safe place before it is disactivated.
  505.  
  506. This problem can be avoided, if the program to be run under AmigaDOS is
  507. only fork()ing, because it just wants to start another process. In that
  508. case, no such copying as described before is necessary, and BSD therefore
  509. invented the `vfork()' function, which works like `fork', but runs the 
  510. child on the parents memory segments (stack and malloc'd data). While the
  511. child is using the parents resources, the parent is sleeping in a not
  512. interruptible state. 
  513.  
  514. That much for theory;-) I tried to implement an as compatible as possible
  515. vfork() function, that behaves like the BSD one. This should work under
  516. any OS version, for Kickstart 1.3 the arp.library is used, starting with
  517. OS 2.0 dos.library is powerful enough to do it itself.
  518.  
  519. Since I won't try to implement `fork', I provided a possible alternative
  520. (you tell me;-)). As an extension, you get the `vfork_resume()' function,
  521. which causes the parent to resume, just like it would if you called 
  522. `_exit()' or one of the `exec*()' functions. Since this function is quite
  523. dangerous (and an even bigger hack than vfork() itself..), here's what's
  524. happening in `vfork_resume()':
  525.  
  526.   o  the child switches to its own stack. After vfork(), the child is
  527.      using the stack of the parent process. Since no two processes can
  528.      share the same stack in parallel, vfork_resume() causes a switch
  529.      to the `real' stack of the child.
  530.   o  the parent is sent a wakeup message.
  531.   o  both processes run concurrently
  532.  
  533. The first point is the most important one: Since vfork_resume() changes
  534. the stack pointer of the running process, you can't refer to any variables
  535. or parameters anymore after calling vfork_resume()! Only register
  536. variables survive such a call, and you have to explicitly store values
  537. in register variables that are subject to survive!
  538.  
  539. There's another potential problem with vfork_resume():
  540.  
  541. **************************************************************************
  542.   Don't exit() from the parent before all vfork()'d children have died!!
  543. **************************************************************************
  544.  
  545. Since exiting from the parent causes the parents code and data segments to
  546. be deallocated, the child would find itself without code space to run
  547. on, and would probably cause a severe machine crash!
  548.  
  549. So always call at least `wait (0)' before returning from the parent.
  550.  
  551.  
  552.  
  553. exec*()
  554. =======
  555.  
  556. In most cases, you just use `vfork()' to later overlay the process with 
  557. a new image, that is you want to start another program. The way AmigaDOS
  558. loads processes is not too well suited to do `exec' style program starting,
  559. yet it is possible, although with slight resource wasting.. 
  560.  
  561. First problem is, that all exec* functions pass an argument vector to
  562. the new program, whereas AmigaDOS programs expect to be passed an argument
  563. line (instead of the vector of arguments). Since in my opinion it would
  564. be a good thing if a program could get an argument vector directly (in that
  565. case the inherent problem of passing multi word arguments to a program would
  566. be finally solved, no more weird quoting needed!). That's why I provided
  567. a mechanism that allows this vector passing, and it works like this (look
  568. at crt0.c for a concrete implementation of this concept!):
  569.  
  570.   The program has to provide a magic header at the first executable location
  571.   in its code. This magic header looks like this:
  572.      o  JMP instruction to common AmigaDOS startup
  573.      o  struct exec area. Use the OMAGIC a_magic code.
  574.      o  provide an alternate entry vector in a_entry. execve() jumps thru
  575.         this vector to pass vectors to your program, instead of going
  576.         thru the normal AmigaDOS startup part.
  577.  
  578. As long as you use my crt0.o and libc.a, this whole thing is completely
  579. transparent to your program, you only have to care for it, if you want
  580. to support the mechanism in other languages as well.
  581.  
  582. The second problem is how to start `old' AmigaDOS programs from execve().
  583. If the program has the described magic header, starting is easy. Else 
  584. another approach is taken, depending on the OS version. Common to both
  585. OS versions (1.3 and 2.0) is redirection of stdin and stdout. Since the
  586. new program can't refer to the real file descriptors (I can't pass the
  587. open library without my startup code), I have to setup DOS fields to
  588. use my filehandles. This may succeed or not, depending on whether the
  589. descriptors in question are realized by DOS files or not (in the future
  590. a not-compatible alternative would be descriptors that refer to sockets!).
  591. Actual starting of the program is done with RunCommand() under 2.0, and
  592. some own hack under 1.3. If someone is interested to get this working
  593. well under 1.3, I'd be happy to include a better starter function, my
  594. kludge doesn't particularly deal graceful with BCPL functions...
  595.  
  596.  
  597.  
  598. Documentation to the provided functions
  599. =======================================
  600.  
  601. I'm a rather lazy guy, and I really hate it writing documentation ;-) 
  602. However, since the library is aimed at emulating as much of BSD as I could
  603. find (more to come ;-)), you can use BSD man pages in almost any situation.
  604. Such man pages can be ftp'd for example from wuarchive.wustl.edu, in
  605. unix/4.3bsd-reno/lib/libc. Look for */*.[1-9] files in that directory
  606. (a nicer way to obtain that information is to download the ls-lR file
  607. from the root, and than to use grep on your local machine!).
  608.  
  609.  
  610.  
  611. Quick guide to those that just want to use the library with GCC
  612. ===============================================================
  613.  
  614. If you're not particularly interested in how things are implemented,
  615. and just want an ANSI compliant C library with gcc, here's what you
  616. have to do.
  617.  
  618. o  unpack the archive (you probably did already ;-))
  619. o  you may delete the following directories, if you don't plan to
  620.    look at the implementation:
  621.      - gnulib/
  622.      - gnulib20/
  623.      - string/
  624.      - stdlib/
  625.      - gen_library/
  626.      - static_library/
  627.      - library/
  628.      - libm/
  629. o  assign gcc: to the base directory, so that you can refer to the
  630.    include/ directory by `gcc:include', and to lib/ by `gcc:lib'.
  631. o  copy libs/ixemul.library into your system libs: directory, or add
  632.    the libs/ directory to LIBS: (only OS 2.0, creating a multi-assign for
  633.    LIBS:).
  634.  
  635. That's it, gcc should now work fine with this library!
  636.  
  637.  
  638.  
  639. What about inline/ headers for 2.0 functions ?
  640. ==============================================
  641.  
  642. I don't use 2.0 functions too often, and I didn't want to distribute
  643. header files I rarely use. The basic step to generate those files 
  644. automatically involves parsing of prototype files and fd files, and
  645. mixing the information together to generate a file of inline function
  646. definitions. Since my current parser is ways too hacky that I would ever
  647. distribute it, if someone else really wants inline headers supporting
  648. 2.0, write the necesssary tool yourself! You might want to contact me
  649. before starting work, so that not multiple people make the same effort
  650. at once.
  651.  
  652.  
  653.  
  654. Some final words
  655. ================
  656.  
  657. I wish you good luck using this library, it isn't that thoroughly tested
  658. yet, but I did manage to recompile gcc with itself using the library, so
  659. some basic reliability should be granted. But keep in mind:
  660.  
  661.     This library is distributed in the hope that it will be useful,
  662.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  663.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  664.     Library General Public License for more details.
  665.  
  666. New versions of the library will first be released on amiga.physik.unizh.ch
  667. in amiga/new, migrating to amiga/devel later.
  668.  
  669. If you like to contribute new functions to the library, please reread
  670. the `What it is and what it isn't' section, and if you think that your
  671. code contributes to those goals, I'd be very happy to include it in
  672. the library in a later release. 
  673. Since indentation style is a great deal a thing of personal taste, 
  674. I make up the following rules:
  675.  o if you change one of the existing files, follow the style of the
  676.    file
  677.  o if you provide a completely new set of functions, you're at your own.
  678.  
  679. If you find bugs in the code (I'm absolutely sure there are some...), please
  680. tell me about them!
  681.  
  682. I'd like to thank specially Michael B. Smith and Michael Bond, who
  683. contributed many bug reports and ideas for improvements, as well as all
  684. the other bug reporters, thank you!
  685.  
  686. Send your bug reports, enhancement requests and constructive remarks to
  687.  
  688.    <wild@nessie.cs.id.ethz.ch>   or   <wild@amiga.physik.unizh.ch>
  689.  
  690. send flames to <bitbucket@nessie.cs.id.ethz.ch> (but don't overflood
  691. nessie's /dev/null please ;-)).
  692.  
  693.  
  694. Markus M. Wild
  695.